<?php
/*
 * @project CreativeFramework
 * @version <#RELEASE_VERSION#>
 * @license GNU Lesser General Public License
 * @author Jimmie Lin
 */

class Hooks {
	/**
	 * run_hooks
	 * Run the hooks that are assigned to the specified position
	 * @param string position
	 * @return bool='true'
	 */
	function run_hooks($position) {
		global $Debug;
		if(!isset($this->hooks_array)) {
			global $DB;
			$this->hooks_array = array();
			$q = $DB->Driver->simple_select("hooks");
			while($a = $DB->Driver->fetch_array($q)) {
				$this->hooks_array[$a['position']][] = $a['file'];
			}
		}
		
		if(isset($this->hooks_array[$position])) {
			foreach($this->hooks_array[$position] as $x) {
				require(HOOKS_PATH.DIRECTORY_SEPARATOR.$x);
				$Debug->writeLog("Ran Hook {$x} on position {$position}", "Hook");
			}
		}
		else {
			$Debug->writeLog("No hooks found on position {$position}, skipping...", "Core");
		}
		return true;
	}
}
